Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow submitting empty data for related fields that are not required #36

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

blturner
Copy link
Contributor

If you have a related field that is not required and you don't submit that field in your data, you get a KeyError when Conduit tries to save the related object.

A request to a Conduit endpoint with an empty object for a FK creates an object with empty attributes and adds a resource_uri attribute that points to the list endpoint for the resource:

{
    'id': 1,
    'name': '',
    'resource_uri': '/api/v1/bar/'
}

This change prevents creating a FK if no data is submitted in the request. If you omit data for a non-required FK field in your request data, then the response will return an empty object in the response:

{
    ...
   'bar': {},
   ...
}

content_type='application/json'
)
content = json.loads(response.content.decode())
self.assertEqual(content['bar'], {})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently the response from the api will return the key with an empty object, but maybe we don't want to have a non-required related field in the response at all if it doesn't exist?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the field is there on the model. It seems to me we should be returning null if the gfk/fk is null and empty list if there are no m2ms.

@blturner blturner changed the title Allow submitting empty data for fks that are not required Allow submitting empty data for related fields that are not required Feb 16, 2015

content_object = content['content_object']
self.assertEqual(content_object['id'], bar.id)
self.assertEqual(content_object['name'], bar.name)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test will fail until #35 if merged in

@akoumjian
Copy link
Owner

Currently working on a complete fix for this. Taking me a while to get back into the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants